package tuathal.snake;

import javax.swing.JLabel;

public class StatusRunnable implements Runnable {
	private Snake snake;
	private JLabel status;
	private JLabel speed;
	private JLabel score;

	public StatusRunnable(Snake snake, JLabel status, JLabel speed, JLabel score) {
		this.snake = snake;
		this.status = status;
		this.speed = speed;
		this.score = score;
	}

	@Override
	public void run() {
		String stat = "";
		String spe = "";
		while (true) {
			switch (snake.status) {
			case Snake.RUNNING:
				stat = "Running";
				break;
			case Snake.PAUSE:
				stat = "Pause";
				break;
			case Snake.GAMEOVER:
				stat = "GameOver";
				break;
			}
			status.setText(stat);
			switch (snake.speed) {
			case Snake.SLOW:
				spe = "Slow";
				break;
			case Snake.MID:
				spe = "Mid";
				break;
			case Snake.FAST:
				spe = "Fast";
				break;
			}
			speed.setText(spe);
			score.setText("" + snake.score);
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if (snake.status == Snake.GAMEOVER) {
				Thread.currentThread().interrupt();
			}
		}
	}
}
